<template>
  <div class="homePage">
    <homeHeader @switchCity="switchCity"></homeHeader>
    <homeJobs :city="city"></homeJobs>
    <bottomMenu :menuType="menuType"></bottomMenu>
    <a :href="telInfo" class="service">
      <img src="/static/wechat/images/service.png" alt="">
    </a>
  </div>
</template>

<script>
  import homeHeader from './homeHeader.vue'
  import homeJobs from './homeJobs.vue'
  import bottomMenu from './bottomMenu.vue'
  import {zgzUser,getBrokers} from'@/controller'
  export default {
    name: 'findJobs',
    data () {
      return {
        msg: 'findJobs',
        menuType:0, // 4代表个人中心
        telInfo:'',
        city:''
      }
    },
    components: {
      'homeHeader': homeHeader,
      'homeJobs': homeJobs,
      'bottomMenu': bottomMenu
    },
    created(){
      this.setScreenHeight();
      let myAgentTel = localStorage.getItem('myAgentTel')
      if(!myAgentTel){
        getBrokers().then((res)=>{
          //暂时先分一个 后面再添加
          this.telInfo = 'tel:'+ res.data[0].brokerPhone
        })
      }else{
        this.telInfo = 'tel:'+ myAgentTel
      }
    },
    methods:{
      setScreenHeight(){
        let data={};
        data.width = document.documentElement.clientWidth;
        data.height = document.documentElement.clientHeight;
        this.$store.dispatch('setScreenSize',data);
      },
      switchCity(city){
        this.city=city
      }
    },
    beforeRouteEnter(to, from, next){
      //判断绑定-缓存不靠谱，通过接口来判断用户是否注册
      // let hasBinding = localStorage.getItem('hasBinding');
      zgzUser().then((data)=>{
        console.log(data);
        if(data.code === 0){
          // this.$store.dispatch('setUserInfo',data.data);
          if(data.data.userPhone!=null)
            localStorage.setItem('hasBind1',true)
          else
            localStorage.setItem('hasBind1',false)
          next()
        }else{
          this.$toast.center('get zgz user error')
        }
      })
    }

  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.homePage{
  padding-bottom: 40px;
}
.service{
    position: fixed;
    top: 60%;
    width: 16%;
    right: 0;
}
.service img{
  width: 100%;
}
</style>
